import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout.vue'
import nowplaying from '../views/nowplaying.vue'
import cinemas from '../views/cinemas/cinemas.vue'
import Pagenotfound from '../views/Pagenotfound.vue'
import commingsoon from '../views/commingsoon.vue'
import film from '../views/film/film.vue'
import mine from '../views/mine/mine.vue'
import Login from '../views/Login.vue'
import city from '../views/city/city.vue'



Vue.use(VueRouter)

const routes = [{
        name: 'Layout',
        path: '/Layout',
        component: Layout,
        alias: '/',
        children: [
            { alias: '/', name: 'nowplaying', path: 'nowplaying', component: nowplaying, meta: { title: '正在热映', animate: true } },
            { name: 'commingsoon', path: '/Commingsoon', component: commingsoon, meta: { title: '即将上映', animate: true } },
            { name: 'cinemas', path: 'cinemas', component: cinemas, meta: { title: '影院列表', animate: false } },
            { name: 'mine', path: 'mine', component: mine, meta: { title: ' ', animate: false, hideheader: true } }
        ]
    },
    { name: 'film', path: '/film/:filmid', component: film, meta: { title: '电影详情', animate: true } },

    { name: 'login', path: '/login', component: Login, meta: { title: '用户登录', animate: false, hideheader: true } },

    { name: 'city', path: '/city', component: city, meta: { title: '城市列表', animate: false, hideheader: true } },

    { name: '404', path: '/404', component: Pagenotfound },
    { path: '*', redirect: '/404' }
]

const router = new VueRouter({
    routes
})


router.afterEach((to, from) => {
    let title = to.meta.title
    if (title) document.title = `我的电影 - ${title}`
    else document.title = '我的电影 - '
});

export default router